package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName BrandController
 * @Author 波
 * @Date 2024/7/28 12:40
 */
@Tag(name = "品牌接口管理")
@RestController
@RequestMapping("/brand")

public class BrandController extends BaseController {

    @Autowired
    private BrandService brandService;

    @Operation(summary = "分页查询品牌列表信息")
    @RequiresPermissions("product:brand:list")
    @GetMapping("/list")
    public TableDataInfo findBrandPageList(Brand brand) {
        startPage();
        List<Brand> brandList = brandService.findBrandPageList(brand);
        return getDataTable(brandList);
    }
    @Operation(summary = "根据ID获取品牌详情信息")
    @GetMapping("/detail/{id}")
    public AjaxResult findBrandDetailInfoById(@PathVariable Long id) {
        return success(brandService.findBrandDetailInfoById(id));
    }
    @Operation(summary = "新增品牌")
    @PostMapping("/add")
    public AjaxResult addBrand(@RequestBody @Validated Brand brand) {
        brand.setCreateBy(SecurityUtils.getUsername());
        return toAjax(brandService.addBrand(brand));
    }
    @Operation(summary = "修改品牌")
    @PutMapping("/update")
    public AjaxResult updateBrand(@RequestBody @Validated Brand brand) {
        brand.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(brandService.updateBrand(brand));
    }
    @Operation(summary = "删除品牌")
    @DeleteMapping("/delete/{ids}")
    public AjaxResult deleteBrand(@PathVariable Long[] ids) {
        return toAjax(brandService.deleteBrand(ids));
    }

    @Operation(summary = "获取全部品牌信息")
    @GetMapping("/getAllBrand")
    public AjaxResult findAllBrand() {
        List<Brand> brandList=brandService.findAllBrand();
        return success(brandList);
    }

    @Operation(summary = "前台获取所有品牌")
    @InnerAuth
    @GetMapping("/getBrandAll")
    public R<List<Brand>> getBrandAll(){
        return R.ok(brandService.findAllBrand());
    }
}
